package model

import (
	"context"
	"service/ctrl"
	"service/model/mod"

	gpb "gitee.com/cloudapex/protos/hr_cache/pb"

	"google.golang.org/grpc"
	"google.golang.org/grpc/status"
)

var StaffCacheServer staffCacheServer

func init() {
	ctrl.GCon.RegistClienter(mod.GCONN_HR_CACHE, func(c *grpc.ClientConn) { StaffCacheServer.cli = gpb.NewStaffCacheServerClient(c) })
}

type staffCacheServer struct {
	cli gpb.StaffCacheServerClient
}

// staffCacheServer.StaffCacheList 员工基本列表
func (this *staffCacheServer) StaffCacheList(ctx context.Context, in *gpb.HrBaseCacheReq, cardId string) (int64, error) {
	var userId int64
	rsp, err := this.cli.GetAllUBaseCache(ctx, in)
	if s := status.Convert(err); s.Err() != nil {
		return userId, s.Err()
	}

	if len(rsp.BaseMap) > 0 {
		for _, v := range rsp.BaseMap {
			if v.NumberId == cardId {
				userId = v.Id
			}
		}
	}
	return userId, err
}
func (this *staffCacheServer) GetStaffCacheInfo(ctx context.Context, in *gpb.HrBaseCacheReq) (*gpb.HrBaseCacheReq, error) {
	return this.cli.GetStaffCacheInfo(ctx, in)
}
func (this *staffCacheServer) GetAllUBaseCache(ctx context.Context, in *gpb.HrBaseCacheReq) (*gpb.HrBaseMap, error) {
	return this.cli.GetAllUBaseCache(ctx, in)
}

// staffCacheServer.AddStaffCacheInfo 添加员工缓存
func (this *staffCacheServer) AddStaffCacheInfo(ctx context.Context, in *gpb.HrBaseCacheReq) (*gpb.HrBaseCacheRes, error) {
	return this.cli.AddStaffCacheInfo(ctx, in)
}

// staffCacheServer.AddStaffCacheInfo 缓存中获取员工信息
func (this *staffCacheServer) GetStaffCacheByNumberId(ctx context.Context, in *gpb.HrBaseCacheReq) (*gpb.HrBaseCacheReq, error) {
	return this.cli.GetStaffCacheByNumberId(ctx, in)
}

// staffCacheServer.GetStaffCacheByWorkId 缓存中获取员工信息
func (this *staffCacheServer) GetStaffCacheByWorkId(ctx context.Context, in *gpb.HrBaseCacheReq) (*gpb.HrBaseCacheReq, error) {
	return this.cli.GetStaffCacheByWorkId(ctx, in)
}

// staffCacheServer.GetStaffNameList 缓存中获取员工信息s
func (this *staffCacheServer) GetStaffNameList(ctx context.Context, in *gpb.StaffNameReqIdsReq) (*gpb.StaffNameListRes, error) {
	return this.cli.GetStaffNameList(ctx, in)
}
